package com.loveprogrammer.cloud.controller;

import com.loveprogrammer.cloud.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 账户Controller
 * @author 钱旭
 * @create 2024-05-27 13:06
 */
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    /**
     * 给指定用户账户扣钱
     * @param amount
     * @param userId
     * @return
     */
    @PostMapping("/decrease")
    public boolean decrease(@RequestParam("amount")Integer amount, @RequestParam("userId")Integer userId){
        System.out.println("amount:"+amount+",userId:"+userId);

        Map<String,Object> map=new HashMap<>();
        map.put("amount",amount);
        map.put("userId",userId);

        accountService.decrease(map);
        return true;

    }

}
